package com.icss.ah.expressBird.thread;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

import net.sf.json.JSONObject;


import com.icss.ah.expressBird.service.ExpressBirdService;
/**
 * 快递鸟回调数据处理线程
 * @author csadchen
 * @date 2017-06-16
 */
public class ExpressBirdThread implements Runnable{
	//错误日志
	private final Logger errlog = Logger.getLogger("E");
	//info日志
	private final Logger infolog = Logger.getLogger("I");
	//商户ID
	private String EBusinessID;
	//快递单记录数
	private int count;
	//数据列表
	private List dataList;
	//快递鸟回调service
	private ExpressBirdService expressBirdService;
	//初始化
	public ExpressBirdThread(String EBusinessID, int count,List dataList,ExpressBirdService expressBirdService) {
        this.EBusinessID = EBusinessID;
        this.count = count;
        this.dataList = dataList;
        this.expressBirdService = expressBirdService;
    }
	//线程执行
	public void run() {
		try{
			//记录日志
			infolog.info("ExpressBirdThread|run|dataList:"+dataList.size());
			for(Iterator<JSONObject> i = dataList.iterator();i.hasNext();){
				JSONObject json = i.next();
				//快递单信息保存
				boolean result = expressBirdService.saveExpressLogistic(json);
				//记录日志
				infolog.info("ExpressBirdThread|run|result:"+result);
			}
		} catch (Exception e) {
			e.printStackTrace();
			//记录日志
			errlog.error("ExpressBirdThread|run|异常：",e);
		}
		
	} 


}
